<?php

namespace App\Modules\Admin\Services\System;

use App\Exceptions\Exception;
use App\Modules\Admin\Entities\System\AgreementModel;
use App\Modules\Admin\Services\BaseService;
use Illuminate\Support\Facades\DB;

class AgreementService extends BaseService
{

    public function __construct(AgreementModel $model)
    {
        $this->model = $model;
    }
    public function getIndexInfo(array $params) : array
    {
        $res =  $this->model->get()->toArray();
        $data=[];
        foreach ($res as $item){
            $data[]=[
                'label'=>$item['title'],
                'value'=>$item['type']
            ];
        }
        return $data;
    }


    public function getAgreementInfo($params)
    {
        $type=$params['type'];

        return $this->model->where(['type'=>$type])->first();
    }
    public function agreementUpdate($params)
    {
        DB::beginTransaction();
        try{
            parent::update($params); // TODO: Change the autogenerated stub
            DB::commit();
            return true;
        }catch (Exception $e){
            DB::rollBack();
            throw new Exception($e->getMessage());
        }
    }
}
